using System;
using System.Collections.Generic;
using System.Text;
using Entities;
using DAL;
using Utility;
namespace BUS
{
    public class tbSanPhamBUS
    {
        public static int  Insert_SP(tbSanPham sanpham)
        {
            tbSanPhamDAL SpDAL = new tbSanPhamDAL();
            return SpDAL.Insert(sanpham);
        }
        public static void Update_SP(tbSanPham sanpham)
        {
            tbSanPhamDAL SpDAL = new tbSanPhamDAL();
            SpDAL.Update(sanpham);
        }
        public static void Delete_SP(int Id)
        {
            tbSanPhamDAL SpDAL = new tbSanPhamDAL();
            SpDAL.Delete(Id);
        }
        public static tbSanPhamCollection Get(string Where, int PageIndex, int PageSize, string OderBy, string OderDirection, out int Total)
        {
            tbSanPhamDAL SanPham_Get = new tbSanPhamDAL();
            return (SanPham_Get.Get(Where, PageIndex, PageSize, OderBy, OderDirection, out Total));
        }
        public static tbSanPhamCollection GetAll()
        {
            int Total = 0;
            tbSanPhamDAL SanPham_GetAll = new tbSanPhamDAL();
            return (SanPham_GetAll.Get("Where 1=1", 0, 0, tbSanPhamColumns.IdSanPham.ToString(), OrderDirection .ASC .ToString (), out Total));
        }
        public static tbSanPham GetId(int Id)
        {
            int Total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, tbSanPhamColumns.IdSanPham.ToString(), Condition.EQUAL, Id);
            tbSanPhamDAL SanPham_GetId = new tbSanPhamDAL();
            tbSanPhamCollection SPColection = SanPham_GetId.Get (cri .Criter ,0,0,tbSanPhamColumns .IdSanPham .ToString (),
                                            OrderDirection .ASC .ToString() ,out Total );
            if (SPColection.Count > 0)
                return SPColection[0];
            return null;
        }
    }
}
